var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
o.levelMapName = void 0;
var r,
    s = cc._decorator,
    c = s.ccclass,
    p = s.property;
s.menu, s.executeInEditMode;
(function (t) {
    t[(t.level1 = 0)] = "level1";
    t[(t.level2 = 1)] = "level2";
})((r = o.levelMapName || (o.levelMapName = {})));
var l = (function (t) {
    i(e, t);
    function e() {
        var e = (null !== t && t.apply(this, arguments)) || this;
        e.lvIndex = r.level1;
        e.tipLab = null;
        e.lay1Node = null;
        e.lay2Node = null;
        e.lay3Node = null;
        e.itemNode = null;
        e.saveIndex = 0;
        e.saveKeyData = {};
        e.saveIndexKeyData = {};
        return e;
    }
    Object.defineProperty(e.prototype, "saveData", {
        get: function () {
            return !1;
        },
        set: function () {
            this.save();
            this.tipLab.string = "存储成功" + this.lvIndex;
        },
        enumerable: !1,
        configurable: !0
    });
    e.prototype.udpataMap = function () {};
    e.prototype.onLoad = function () {
        this.udpataMap();
    };
    e.prototype.getParseData = function (t) {
        for (var e = {}, o = t.getComponentsInChildren(cc.Sprite), a = 0; a < o.length; a++) {
            var i = o[a].node,
                n = this.getSpriteName(o[a]);
            if ("" != n) {
                if (!this.saveKeyData[n]) {
                    this.saveIndex++;
                    this.saveKeyData[n] = this.saveIndex;
                    this.saveIndexKeyData[this.saveIndex] = n;
                }
                e[a] = {x: i.x, y: i.y, sx: i.scaleX, sy: i.scaleY, r: i.angle || 0, spf: this.saveKeyData[n]};
            } else console.log("EditorLevelCom ----------------- 没获取到地图");
        }
        return e;
    };
    e.prototype.getSpriteName = function (t) {
        var e = "",
            o = t;
        o && null != o.spriteFrame && (e = o.spriteFrame.name);
        return e;
    };
    e.prototype.getSaveData = function () {
        var t = {};
        this.saveIndex = 0;
        this.saveKeyData = {};
        this.saveIndexKeyData = {};
        t.ver = "1.0.0";
        t.tip = "关卡" + this.lvIndex;
        t.data = {};
        t.data[0] = this.getParseData(this.lay1Node);
        t.data[1] = this.getParseData(this.itemNode);
        t.data[2] = this.getParseData(this.lay2Node);
        t.data[3] = this.getChildItem(this.lay3Node);
        t.data.c = this.saveIndexKeyData;
        return t;
    };
    e.prototype.getChildItem = function (t) {
        for (var e = {}, o = t.children, a = 0; a < o.length; a++) {
            for (var i = [], n = o[a].children, r = 0; r < n.length; r++) {
                var s = n[r].getComponent(cc.Sprite);
                i.push({x: n[r].x, y: n[r].y, name: this.getSpriteName(s)});
            }
            e[a] = i;
        }
        return e;
    };
    e.prototype.getMapName = function () {
        return "level" + (this.lvIndex + 1) + ".json";
    };
    e.prototype.save = function () {
        var t = this.getMapName(),
            e = this.getSaveData();
        console.log("EditorCom -----------------接续的数据 " + t, e);
        d.saveFileInAssets("/Res/map/", t, JSON.stringify(e));
    };
    e.prototype.init = function () {};
    n([p({type: cc.Enum(r)})], e.prototype, "lvIndex", void 0);
    n([p(cc.Label)], e.prototype, "tipLab", void 0);
    n([p(cc.Node)], e.prototype, "lay1Node", void 0);
    n([p(cc.Node)], e.prototype, "lay2Node", void 0);
    n([p(cc.Node)], e.prototype, "lay3Node", void 0);
    n([p(cc.Node)], e.prototype, "itemNode", void 0);
    n([p({displayName: "存储"})], e.prototype, "saveData", null);
    return n([c], e);
})(cc.Component);
o.default = l;
var d = (function () {
    function t() {}
    t.saveFile = function () {};
    t.saveFileInAssets = function (t, e, o) {
        this.saveFile("assets/" + t, e, o);
    };
    return t;
})();
